package com.sky.mapper;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Goods;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    void save(Orders orders);

    Integer count(Integer status, Long userId);

    List<Orders> pageQuery(Integer start, Integer pageSize, Integer status, Long userId);

    @Select("select * from orders where id = #{id};")
    Orders getById(Long id);

    void update(Orders orders);

    List<Orders> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO);

    Integer conditionCount(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select count(*) from orders where status = #{status}")
    Integer countStatus(Integer status);

    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> getByStatusAndOrderTime(Integer status, LocalDateTime time);

    @Select("select * from orders where order_time between #{beginTime} and #{endTime} and status = 5 order by order_time")
    List<Orders> getByStatusAndBeginAndEnd(LocalDateTime beginTime, LocalDateTime endTime);

    Integer countByMap(Map map);

    @Select("select od.name name, sum(od.number) count from orders o, order_detail od where o.id = od.order_id and o.order_time between #{begin} and #{end} and o.status = 5 " +
            "group by od.name order by sum(od.number) desc limit 0, 10")
    List<Goods> getTop10(LocalDateTime begin, LocalDateTime end);


    Double sumByMap(Map map);
}
